/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

import edu.pku.sei.modeler.uml.ResourceFactory;

/**
 * @generated
 * 
 */
public class UMLClassFigure extends CommonFigure {

	public static final Color CLASS_COLOR = ColorConstants.lightBlue;

	private IFigure body;

	private Label nameLabel;

	private Figure attributeContainerFigure;

	private Figure operationContainerFigure;

	public UMLClassFigure(final Label header) {
		// this.header = header;
		ToolbarLayout layout = new ToolbarLayout();
		setLayoutManager(layout);
		// layout.setSpacing(2);

		setBorder(new LineBorder(1));
		// setOpaque(true);

		setForegroundColor(CLASS_COLOR);
		
		body = new Figure();
		body.setForegroundColor(CLASS_COLOR);
		ToolbarLayout bodyLayout = new ToolbarLayout();

		bodyLayout.setVertical(true);
		body.setLayoutManager(bodyLayout);
		
		if (header.getText().length() > 0) {
			body.add(header);
		}
		//	
		
		nameLabel = new Label();
		nameLabel.setFont(ResourceFactory.getHeadFont());
		nameLabel.setForegroundColor(ColorConstants.black);	
		body.add(nameLabel);
		nameLabel.setFont(ResourceFactory.getHeadFont());
		nameLabel.setLabelAlignment(PositionConstants.CENTER);
		
		attributeContainerFigure = new ContainerFigure();
		attributeContainerFigure.setForegroundColor(CLASS_COLOR);
		attributeContainerFigure.setBackgroundColor(nameLabel.getBackgroundColor());
		
		operationContainerFigure = new ContainerFigure();
		operationContainerFigure.setForegroundColor(CLASS_COLOR);
		operationContainerFigure.setBackgroundColor(nameLabel.getBackgroundColor());
		setOpaque(true);
		//	
		//TODO reference		
		// // if(reference) {
		// // body.add(nameLabel);
		// //}
		body.add(attributeContainerFigure);

		body.add(operationContainerFigure);

		add(body);
	}
	
	public void changeLineColor(Color color) {
		if (color != null) {
			this.setForegroundColor(color);
			body.setForegroundColor(color);
			attributeContainerFigure.setForegroundColor(color);
			operationContainerFigure.setForegroundColor(color);
		}
	}
	
	public Label getNameLabel() {
		return nameLabel;
	}

	public Figure getAttrCompart() {
		return attributeContainerFigure;
	}

	public Figure getOpCompart() {
		return operationContainerFigure;
	}
}
